<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$app->get('/', function () use ($app) {
    return view('test');
});

$app->get('index/',function () use ($app){
    if(isset($_GET['user_info'])){
        $user_info = json_decode($_GET['user_info'],true);
        return view('index',$user_info);
    }else{
        $redirect_uri = 'http://weixin.51ffeng.cn/login?url=http://weixin.51ffeng.cn/index?user_info=';
        $uri = 'http://'.$_SERVER['HTTP_HOST'].'/oauth?redirect_uri='.urlencode($redirect_uri);
        header("Location: $uri");
    }
});

$app->get('login/',function () use ($app){
	$url = $_GET['url'];
    $user = file_get_contents('http://weixin.51ffeng.cn/weixin/get_user_info?code='.$_GET['code']);
    $user = json_decode($user);
    if(isset($user->result)){
        $url = $url.json_encode($user->result);
        header("Location: $url");
    }
});
$app->get('proxy/','ProxyController@index');
$app->get('oauth/','OauthController@index');
$app->get('weixin/get_user_info','WeixinController@get_user_info');
$app->post('pay/unifiedorder','WeixinController@unifiedorder');
$app->get('pay/','PayController@index');

